* Master file
version 16

clear all
set more off

*****************************************************************************
* TO REPRODUCE THE ANALYSIS, PLEASE CHANGE DIRECTORY PATHS IN LINES 17-20   *
* TO THE RESPECTIVE FOLDERS ON YOUR COMPUTER. NO OTHER CHANGES SHOULD 		*
* BE NECESSARY.																*			
*																			*
* THE ENTIRE ANALYSIS IS DONE IN STATA. HOWEVER, R IS USED TO PLOT FIGURES.	*
*																			*		
*****************************************************************************

* Directories
global data C:\...\6614STATA_B6053CF165E80880E9DBB332912108F5_001\UKDA-6614-stata\stata\stata11_se // Path to BHPS data (UKDA 6614)
global BHPSlifehistory C:\...\UKDA-7821-stata13\code\stata\data // Path to BHPS data (UKDA 7821)

global codedir C:/ 
global outputdir C:/

cd $outputdir


******* Ensure required subfolders exist
cap mkdir data
cap mkdir temp
cap mkdir figs
cap mkdir tables
cap mkdir logs

******* Sets up the log for the output
local date : di  %tdCY-N-D  daily("$S_DATE", "DMY")
local h=substr(c(current_time),1,2)
local m=substr(c(current_time),4,2)
local s=substr(c(current_time),7,2)

cap log close
log using "logs/`date'-`h'-`m'-`s'", text

* System information
about 
ado dir


******** Fetch original data files and combine
noisily include $codedir/10_bhps_maindata_merge.do
	
******** Fetch work-life histories and prepare for merging
noisily include $codedir/10_bhps_worklifehistories.do
		
******** Clean data and create variables
noisily include $codedir/20_data_wrangling.do

******** Run analysis reported in main paper
noisily include $codedir/30_figure1.do

noisily include $codedir/30_figure2.do


******** Run auxilliary analysis 

noisily include $codedir/30_figure1_B3.do
noisily include $codedir/30_figure1_B4.do
noisily include $codedir/30_figure1_B5.do
noisily include $codedir/30_figure1_B6.do
noisily include $codedir/30_figure1_B7.do

noisily include $codedir/30_figure2_C4.do
noisily include $codedir/30_figure2_C5.do
noisily include $codedir/30_figure2_C6.do
noisily include $codedir/30_figure2_C7.do

noisily include $codedir/30_figureD1.do

log close

